#include <bits/stdc++.h>
using namespace std;

int T, n, a[200007], b[200007];
long long ans = 0;

long long f(long long p, int rdd, int bld){
	memset(b, 0, sizeof(b));
	long long res = 0;
	for(int i = 1; i <= n; i++) b[i] = p % 2, p >>= 1;
	for(int i = 1; i <= n; i++){
		if(b[i] == 1){ res += (a[i] == a[rdd] ? a[i] : 0); rdd = i; }
		if(b[i] == 0){ res += (a[i] == a[bld] ? a[i] : 0); bld = i; }
	}
	return res;
}

int main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	scanf("%d", &T);
	while(T--){
		ans = 0;
		scanf("%d", &n);
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for(long long i = 0; i < (1 << n); i++)
			ans = max(ans, f(i, 0, 0));
		printf("%lld\n", ans);
	}
	return 0;
}
